$(function () {
    LoginStatus();

    var userInfo = JSON.parse($.cookie('userInfo'));
    var companyInfo = JSON.parse($.cookie('companyInfo'));

    $('#userAvatar').attr('src', companyServices + userInfo.img);
    $('#userName').text((userInfo.name == '' || userInfo.name == null) ? "":userInfo.name);
    $('#userPosition').text((userInfo.position == '' || userInfo.position == null) ? "":userInfo.position);

    $('#companyLogo').attr('src', companyServices + companyInfo.logo);
    $('#companyFullNameTop').text((companyInfo.fullName == '' || companyInfo.fullName == null)? "":companyInfo.fullName);
    $('#companyFullName').text((companyInfo.fullName == '' || companyInfo.fullName == null) ? "":companyInfo.fullName);
    $('#companySimpleName').text((companyInfo.simpleName == '' || companyInfo.simpleName == null) ? "":companyInfo.simpleName);
    $('#industry').text((companyInfo.industryName == '' || companyInfo.industryName == null) ? "":companyInfo.industryName);
    $('#companyId').val(companyInfo.id);
})
layui.use(['form'], function () {

    var $ = layui.$, form = layui.form;


    form.on('submit(btnSave)', function (data) {

        layer.load(2);
        $.ajax({
            type: 'post', // 提交方式 get/post
            url: companyServices+"/user/join/company/" + data.field.companyId, // 需要提交的 url
            contentType:"application/json;charset=utf-8",
            xhrFields: {
                withCredentials: true
            }
            ,crossDomain: true
            ,data:{},
            success: function(res) {
                layer.closeAll('loading');
                if(res.status == '00200'){
                    $.removeCookie('companyInfo');
                    layerMsg(res.message);
                    setTimeout(function() {
                        window.location.href="../login.html" ;
                    },2000);

                }else{
                    layerMsg(res.message)
                }
            },fail:function () {
                layer.closeAll('loading');
            }
        })


        return false;
    });




});